package cn.wolfcode.shop.listener;

import cn.wolfcode.shop.redis.GoodPrefixKey;
import cn.wolfcode.shop.redis.RedisService;
import cn.wolfcode.shop.service.ISeckillGoodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * Created by wolfcode-lanxw
 */
@Component
public class InitListener implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private ISeckillGoodService seckillGoodService;
    @Autowired
    private RedisService redisService;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        if(!redisService.exists(GoodPrefixKey.GOOD_HASH,"")){
            seckillGoodService.query();
        }
    }
}
